#include <iostream>
#include "ElectricalAppliance.hpp"

using namespace std;


void ElectricalAppliance::setPower(Power *p)
{
    power = p;
}

bool ElectricalAppliance::boot()
{
    // 精度容忍度
    const double Precision = 0.01;
    // 计算电源误差
    double error = abs((getValidInput() - power->output()) / getValidInput());
    if (error <= Precision)
    {
        cout << "设备成功启动" << endl;
        return true;
    }
    else
    {
        cout << "电源输入不匹配，设备启动失败" << endl;
        return false;
    }
}